home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Ebooks / Thinking in C++ V2 / C18 / Strmove.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-25  |  602 b   |  22 lines

  1. //: C18:Strmove.cpp
  2. // From Thinking in C++, 2nd Edition
  3. // Available at http://www.BruceEckel.com
  4. // (c) Bruce Eckel 1999
  5. // Copyright notice in Copyright.txt
  6. // ostrstream memory movement
  7. #include <iostream>
  8. #include <strstream>
  9. using namespace std;
  10.  
  11. int main() {
  12.   ostrstream s;
  13.   s << "hi";
  14.   char* old = s.str(); // Freezes s
  15.   s.rdbuf()->freeze(0); // Unfreeze
  16.   for(int i = 0; i < 100; i++)
  17.     s << "howdy"; // Should force reallocation
  18.   cout << "old = " << (void*)old << endl;
  19.   cout << "new = " << (void*)s.str(); // Freezes
  20.   delete s.str(); // Release storage
  21. } ///:~
  22.